#include <stdio.h>
#include <stdlib.h>
typedef struct List{
    char ch;
    struct List* next;
} list;
list* HeadPointer(void);
void LinkedList(list*);
void DeleteChar(list *, char);
void EraseChar(list*, char);
void PrintString(list*);
int main(void){
    char ch;
    list *p = HeadPointer();
    printf("Please enter a string:\n");
    LinkedList(p);
    printf("Please enter the character you want to delete:  \n");
    scanf(" %c", &ch);
    EraseChar(p, ch);
    PrintString(p);
    return 0;
}
list* HeadPointer(void){
    list *pHead = (list*)malloc(sizeof(list));
    pHead->next = NULL;
    return pHead;
}
void LinkedList(list* pHead){
    list *tmp = pHead, *tail;
    do{
        tail = (list*)malloc(sizeof(list));
        tail->next = NULL;
        tail->ch = getchar();
        tmp->next = tail;
        tmp = tail;
    } while (tail->ch != '\n');
}
void DeleteChar(list *pHead, char c){
    list *head = pHead, *tail = pHead->next;
    while (tail->ch != c){
        head = head->next;
        tail = tail->next;
    }
    head->next = tail->next;
    free(tail);
}
void EraseChar(list *pHead, char c){
    list *tmp = pHead->next;
    while (tmp){
        if (tmp->ch == c)
            DeleteChar(pHead, c);
        tmp = tmp->next;
    }
    if (tmp->next == NULL && tmp->ch != c){
        printf("The character is not in the string.\n");
        return;
    }
}
void PrintString(list *pHead){
    list *p = pHead->next;
    while (p){
        printf("%c", p->ch);
        p = p->next;
    }
    putchar('\n');
}

